package com.gr.staffpm.pages.tasks;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountHybrid;

import com.gr.staffpm.StaffPMWebPage;
import com.gr.staffpm.datatypes.Task;
import com.gr.staffpm.security.service.UserService;
import com.gr.staffpm.tasks.service.TaskService;

@MountHybrid
@MountPath(path = "secure/EditTask")
public class EditTask extends StaffPMWebPage {

    @SpringBean(name = "taskService")
    private TaskService taskService;
    @SpringBean(name = "userService")
    private UserService userService;
    private final Task task;

    public EditTask(PageParameters parameters) {
        super();
        this.task = taskService.getTask(parameters.getInt("id"));
        super.onBeforeRender();

        if (task.getStatus().equals(taskService.getClosedStatus()) || task.isQueued()) {
            setResponsePage(ViewTask.class, new PageParameters("id=" + task.getTaskId()));
        } else {
            //Header
            add(new Label("projectName", "Project: " + task.getProject().getProjectName()));
            add(new Label("taskName", "Task: " + task.getName()));

            add(new FeedbackPanel("feedback"));

            //Form
            add(new EditTaskForm("editTaskForm", userService, taskService, task));
        }

    }

    @Override
    public String getTitle() {
        return "Edit Task: " + task.getName() + " - StaffPM";
    }

}
